package com.p2p.backend.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.p2p.base.dao.BaseMapper;
import com.p2p.base.page.PageVo;

/**
 * leiwen@yiqihao.com
 */
public interface PrivilegeDao extends BaseMapper {

	@Select("select * from p2p_privilege where acl=#{acl}")
	Map<String, Object> get(Integer acl);
	
	@Select("select * from p2p_privilege where parent_acl=#{acl}")
	List<Map<String, Object>> listChild(Integer acl);
	
	@Select("select * from p2p_privilege")
	List<Map<String, Object>> listPage(PageVo page);
	
	@Select("select * from p2p_privilege")
	List<Map<String, Object>> listAll();
	
	@Select("select * from p2p_privilege where ismenu=1")
	List<Map<String, Object>> listAllMenu();
	
	List<Map<String, Object>> findAllByUserId(Long userId);
	
	@Insert("insert into p2p_privilege(parent_acl,name,enname,sort_no,url,ismenu) values (#{parent_acl},#{name},#{enname},#{sort_no},#{url},#{ismenu})")
	void add(Map<String, Object> privilege);

	@Update("update p2p_privilege set parent_acl=#{parent_acl},name=#{name},enname=#{enname},sort_no=#{sort_no},url=#{url},ismenu=#{ismenu} where acl=#{acl}")
	void update(Map<String, Object> privilege);

	// 物理删除
	@Delete("delete from p2p_privilege where acl=#{acl} or parent_acl = #{acl}")
	void delete(Integer acl);






}
